<template>
  <div class="app-container">
    <el-form :model="queryParam" ref="queryForm" :inline="true">
      <el-form-item label="班级名称：">
        <el-input v-model="queryParam.className" filterable clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">查询</el-button>
     <router-link :to="{path:'/class/grade/search'}" class="link-left">
          <el-button type="primary">个人成绩查询</el-button>
      </router-link>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="id" label="班级编号"  width="280" align="center"/>
      <el-table-column prop="className" label="班级名称" align="center"/>
      <el-table-column prop="stuCount" label="人数" width="280" align="center"/>
      <el-table-column width="360px" label="操作" align="center">
        <template slot-scope="{row}">
          <router-link :to="{path:'/class/grade/all', query:{id:row.id}}" class="link-left">
            <el-button size="mini" >查看成绩</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
                @pagination="search"/>
  </div>
</template>

<script>
// import { mapGetters, mapState } from 'vuex'
// import Pagination from '@/components/Pagination'
// import classApi from '@/api/class'

export default {
  components: { Pagination },
  data () {
    return {
      queryParam: {
        className: null,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created () {
    this.search()
  },
  methods: {
    search () {
      this.listLoading = true
      classApi.getClassPageList(this.queryParam).then(data => {
        const re = data.response
        this.tableData = re.list
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.listLoading = false
      })
    },
    submitForm () {
      this.queryParam.pageIndex = 1
      this.search()
    },
    statusFormatter (isEnabled) {
      return this.enumFormat(this.statusEnum, isEnabled)
    },
    statusTagFormatter (isEnabled) {
      return this.enumFormat(this.statusTag, isEnabled)
    },
    statusBtnFormatter (isEnabled) {
      return this.enumFormat(this.statusBtn, isEnabled)
    }
  },
  computed: {
    ...mapGetters('enumItem', [
      'enumFormat'
    ]),
    ...mapState('enumItem', {
      statusEnum: state => state.class.statusEnum,
      statusTag: state => state.class.statusTag,
      statusBtn: state => state.class.statusBtn
    })
  }
}
</script>
